package de.clapp.musicbox.loader;

import java.util.ArrayList;

import android.content.Context;
import android.support.v4.content.AsyncTaskLoader;
import de.clapp.CLAppModel;
import de.clapp.Settings;
import de.clapp.backend.network.ClientRequest;
import de.clapp.backend.network.TCPSocket;
import de.clapp.backend.requests.MusicListRequest;
import de.clapp.data.Club;
import de.clapp.data.MusicItem;
import de.clapp.toolkit.ImageManager;

public class MusicBoxLoader extends AsyncTaskLoader<ArrayList<MusicItem>>
{
    public static final int MUSICBOXLOADER_ID = 100;

    public MusicBoxLoader(Context context)
    {
        super(context);
    }

    @Override
    public ArrayList<MusicItem> loadInBackground()
    {
        MusicListRequest request = new MusicListRequest();
        ArrayList<MusicItem> songList = null;

        try
        {
            Club club = CLAppModel.getInstance().getCurrentClub();
            ClientRequest cr = new ClientRequest(new TCPSocket(club.getIpAddress(), club.getPort()));
            cr.request(request);
            songList = request.getItem();
            cr.close();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return songList;
    }

}
